package com.nineclock.auth.exception;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.ser.std.StdSerializer;

import java.io.IOException;


/**
 * @author lenovo
 */
public class NcOAuthExceptionJacksonSerializer extends StdSerializer<NcOAuth2Exception> {

    public NcOAuthExceptionJacksonSerializer() {
        super(NcOAuth2Exception.class);
    }

    @Override
    public void serialize(NcOAuth2Exception e, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException {
            jsonGenerator.writeStartObject();
            jsonGenerator.writeObjectField("success",false);
            jsonGenerator.writeObjectField("code",e.getHttpErrorCode());
            jsonGenerator.writeObjectField("message",e.getMessage());
            jsonGenerator.writeEndObject();
    }
}
